home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1599 / 1252 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  3.8 KB

  1. Subject: mintlib getpw* open file, isatty...
  2. Date: Sat, 26 Mar 94 22:39:46 CET
  3. From: Juergen Lock <nox@jelal.north.de>
  4. Message-Id: <9403262139.AA00297@jelal.north.de>
  5.  
  6. 1. getpwnam + getpwuid left the passwd file open and then try to reuse
  7. the open FILE * later, no good if a program closes all open fds before
  8. a fork etc.  (rebuilt uucp with new libs and suddenly file requests end
  9. up with getpwnam hanging in a blocking read from the modem line... :)
  10.  
  11. Index: getpw.c
  12. @@ -299,9 +299,12 @@
  13.  {
  14.    setpwent();
  15.    while (nextent(fp) != 0)
  16. -    if (curentry.pw_uid == uid)
  17. +    if (curentry.pw_uid == uid) {
  18. +      endpwent();
  19.        return(&curentry);
  20. +    }
  21.  
  22. +  endpwent();
  23.    return(NULL);
  24.  } /* End of getpwuid() */
  25.  
  26. @@ -312,9 +315,12 @@
  27.    setpwent();
  28.  
  29.    while (nextent(fp) != 0)
  30. -    if (strcmp(curentry.pw_name, name) == 0)
  31. +    if (strcmp(curentry.pw_name, name) == 0) {
  32. +      endpwent();
  33.        return(&curentry);
  34. +    }
  35.  
  36. +  endpwent();
  37.    return(NULL);
  38.  } /* End of getpwnam() */
  39.  
  40. 2. save 1 or 2 system calls in isatty and make it work more often on
  41. reused fds that were not closed thru close.  there still is the case
  42. fd not opened thru the lib, like named pipes and ptys because they need
  43. special Fcreate modes.  (hmm another reason why we should better have a
  44. real mknod or at least some kind of emulation for named pipes/ptys... :)
  45.  
  46. Index: isatty.c
  47. @@ -21,19 +21,26 @@
  48.    int rc;
  49.    long oldloc;
  50.    int handle = __OPEN_INDEX(fd);
  51. +  extern int __mint;
  52.  
  53.    if (handle < __NHANDLES)
  54.      if (__open_stat[handle].status != FH_UNKNOWN)
  55.          return(__open_stat[handle].status == FH_ISATTY);
  56. -  oldloc = Fseek(0L, fd, SEEK_CUR);    /* save current location */
  57. -  if (Fseek(1L, fd, SEEK_CUR) != 0) {    /* try to seek ahead one byte */
  58. -    /* got either a file position or an error (usually EBADARG indicating
  59. -       a range error from trying to seek past EOF), so it is not a tty */
  60. -    rc = 0;
  61. -    (void) Fseek(oldloc, fd, SEEK_SET);    /* seek back to original location */
  62. +  if (__mint) {
  63. +    /* save 1 or 2 system calls (isatty gets called on every open...) */
  64. +    long dummy;
  65. +    rc = (Fcntl(fd, &dummy, TIOCGPGRP) == 0);
  66. +  } else {
  67. +    oldloc = Fseek(0L, fd, SEEK_CUR);    /* save current location */
  68. +    if (Fseek(1L, fd, SEEK_CUR) != 0) {    /* try to seek ahead one byte */
  69. +      /* got either a file position or an error (usually EBADARG indicating
  70. +     a range error from trying to seek past EOF), so it is not a tty */
  71. +      rc = 0;
  72. +      (void) Fseek(oldloc, fd, SEEK_SET);/* seek back to original location */
  73. +    }
  74. +    else
  75. +      rc = 1;                /* yes, tty */
  76.    }
  77. -  else
  78. -    rc = 1;                /* yes, tty */
  79.    if (handle < __NHANDLES)
  80.      if (rc) {
  81.          __open_stat[handle].status = FH_ISATTY;
  82. Index: open.c
  83. @@ -164,6 +164,9 @@
  84.      if ((iomode & O_APPEND) && !(modemask & _REALO_APPEND))
  85.          (void)Fseek(0L, rv, SEEK_END);
  86.  
  87. +    /* fix the case `isatty() called before and not closed thru close()' */
  88. +    if (__OPEN_INDEX(rv) < __NHANDLES)
  89. +        __open_stat[__OPEN_INDEX(rv)].status = FH_UNKNOWN;
  90.       /* Important side effect:  isatty(rv) sets up flags under TOS */
  91.      if (isatty(rv) && (!(iomode & O_NOCTTY)) && (!(isatty(-1)))) {
  92.            /* If the process is a session leader with no controlling tty,
  93. Index: pipe.c
  94. @@ -7,6 +7,7 @@
  95.  #include <errno.h>
  96.  #include <mintbind.h>
  97.  #include <unistd.h>
  98. +#include "lib.h"
  99.  
  100.  int
  101.  pipe(fd)
  102. @@ -22,5 +23,10 @@
  103.      }
  104.      fd[0] = mint_handle[0];
  105.      fd[1] = mint_handle[1];
  106. +    /* fix the case `isatty() called before and not closed thru close()' */
  107. +    if (__OPEN_INDEX(fd[0]) < __NHANDLES)
  108. +        __open_stat[__OPEN_INDEX(fd[0])].status = FH_UNKNOWN;
  109. +    if (__OPEN_INDEX(fd[1]) < __NHANDLES)
  110. +        __open_stat[__OPEN_INDEX(fd[1])].status = FH_UNKNOWN;
  111.      return 0;
  112.  }
  113. -- 
  114. J"urgen Lock / nox@jelal.north.de / UUCP: ..!uunet!unido!uniol!jelal!nox
  115.                                 ...ohne Gewehr
  116. PGP public key fingerprint =  8A 18 58 54 03 7B FC 12  1F 8B 63 C7 19 27 CF DA 
  117.